/*    */ package com.qmsk.business.htmlUtils.controller;
/*    */ 
/*    */ import com.utils.web.RequestUtils;
/*    */ import com.utils.web.ResponseUtils;
/*    */ import java.io.ByteArrayOutputStream;
/*    */ import java.io.InputStream;
/*    */ import java.net.HttpURLConnection;
/*    */ import java.net.URL;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.apache.log4j.Logger;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ 
/*    */ @Controller
/*    */ @RequestMapping({"/htmlUtils"})
/*    */ public class HtmlUtilsController
/*    */ {
/* 24 */   private static final Logger logger = Logger.getLogger(HtmlUtilsController.class);
/*    */ 
/*    */   @RequestMapping(value={"find/getHtml"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*    */   public void getHtmlRsult(HttpServletRequest request, HttpServletResponse response)
/*    */   {
/* 36 */     String htmlUrl = RequestUtils.getString(request, "htmlUrl", null);
/*    */     try
/*    */     {
/* 39 */       String htmlSource = readInputStream(htmlUrl);
/*    */ 
/* 41 */       String[] head = { "htmlStr" };
/* 42 */       Object[] datas = { htmlSource };
/* 43 */       ResponseUtils.toGsonEbRst(head, datas, response);
/*    */     }
/*    */     catch (Exception e) {
/* 46 */       logger.error(e);
/* 47 */       ResponseUtils.setErrorMsgResponse(
/* 48 */         RequestUtils.getFindDataErrorMessage(request), response);
/*    */     }
/*    */   }
/*    */ 
/*    */   public static String readInputStream(String htmlUrl) {
/*    */     try {
/* 54 */       URL url = new URL(htmlUrl);
/* 55 */       HttpURLConnection conn = (HttpURLConnection)url.openConnection();
/* 56 */       conn.setRequestMethod("GET");
/* 57 */       conn.setConnectTimeout(5000);
/* 58 */       InputStream inStream = conn.getInputStream();
/* 59 */       ByteArrayOutputStream outStream = new ByteArrayOutputStream();
/* 60 */       byte[] buffer = new byte[1204];
/* 61 */       int len = 0;
/* 62 */       while ((len = inStream.read(buffer)) != -1) {
/* 63 */         outStream.write(buffer, 0, len);
/*    */       }
/* 65 */       inStream.close();
/* 66 */       byte[] data = outStream.toByteArray();
/* 67 */       return new String(data, "utf-8"); } catch (Exception e) {
/*    */     }
/* 69 */     return "";
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.htmlUtils.controller.HtmlUtilsController
 * JD-Core Version:    0.5.3
 */